package com.crazyteam.genid.model;

import com.crazyteam.genid.constant.GenIdConstant;

import java.io.Serializable;


/**
 * @Desc
 * @Author guoyang
 * @CreateTime 2016-3-3 下午01:27:45
 */
public class KeyBuffer implements Serializable {

    private static final long serialVersionUID = 1735145023810342218L;

    /**
     * 最小值
     */
    private long min = GenIdConstant.UNDER_LIMIT;
    /**
     * 最大值
     */
    private long max = GenIdConstant.UNDER_LIMIT;
    /**
     * 当前值(已经使用到此值，并且已经被使用)
     */
    private long current = GenIdConstant.UNDER_LIMIT;
    
    /**步长*/
    private Integer inc = GenIdConstant.INC_DEFAULT;

    public long getMin(){
        return min;
    }

    public void setMin(long min){
        this.min = min;
    }

    public long getMax(){
        return max;
    }

    public void setMax(long max){
        this.max = max;
    }

    public long getCurrent(){
        return current;
    }

    public void setCurrent(long current){
        this.current = current;
    }

    public boolean hasNext(){
        return current + inc - 1 < max;
    } 

    public long nextValue(){
    	current = current + inc;
        return current;
    } 

    public void copy(KeyBuffer buff){
        this.max = buff.getMax();
        this.min = buff.getMin();
        this.current = buff.getCurrent();
    }

	public Integer getInc() {
		return inc;
	}

	public void setInc(Integer inc) {
		this.inc = inc;
	}
}
